import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;

public class LineCounter
{
	static int count;
	static int fileCount;
	
	public static void main(String[] args)
	{
		try
		{
			File root = new File(".");
			count(root);
			System.out.println();
			System.out.println();
			System.out.println("Files: "+fileCount);
			System.out.println("Lines: "+count);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	private static void count(File root)
		throws Exception
	{
		if (root.getName().equals("target"))
			return;
		
		File files[] = root.listFiles();
		
		for (File file:files)
		{
			if (file.isDirectory())
				count(file);
			else
			{
				if (file.getName().endsWith(".java"))
				{
					fileCount++;
					System.out.println(file.getAbsolutePath());
					FileInputStream reader = new FileInputStream(file);
					DataInputStream stream = new DataInputStream(reader);
					
					String line = stream.readLine();
					
					while (line != null)
					{
						count ++;
						line = stream.readLine();
					}
					
					stream.close();
					reader.close();
				}
			}
		}
	}
}
